import io
import matplotlib.pyplot as plt
import numpy as np
import sys as ss

def plotmy():
        xlist = np.linspace(0, 360, 100)
        ylist = np.linspace(0, 10, 100)
        X, Y = np.meshgrid(xlist, ylist)
        print("+++++++++++++++++++++++++++++++++++++ X ="+str(X))
        Z = np.sqrt(X**2 + Y**2)
        print("+++++++++++++++++++++++++++++++++++++ Z ="+str(Z))
        fig,ax=plt.subplots(1,1)
        ax1 = plt.gca()
        ax1.xaxis.set_ticks_position('top')

        #ax1.invert_xaxis()  #x轴反向
        ax1.invert_yaxis()  #y轴反向
        cp = ax.contourf(X, Y, Z)
        fig.colorbar(cp) # Add a colorbar to a plot
        ax.set_title('Filled Contours Plot')
        #ax.set_xlabel('x (cm)')
        ax.set_ylabel('y (cm)')

        f = io.BytesIO()
        plt.savefig(f, format="png")
        return f.getvalue()

def sendCurve(rx_voltage):#python 将string转float数组
        #print("--------------11111111111111111111111111--------------"+str(rx_voltage))
        list_int = []
        list_float = []
        list_float = rx_voltage.strip(',').split(",")
        for i in range(len(list_float)):

                list_int.append(float(list_float[i]))
        print("------rx_voltage py=")
        print(list_int)
        #plt.plot(list_float,'r', label='tx_vol')
        plt.plot(list_int,'g', label='tx_vol')
        plt.xlabel('count')
        #plt.ylabel('Y')
        plt.title('Simple Scatterplot')
        #plt.grid(True) ##??????
        plt.pause(0.5)
        f = io.BytesIO()
        plt.savefig(f, format="png")
        return f.getvalue()
